package com.itheima.mall.service.omsService;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.PageResult;
import com.itheima.dto.OmsOrderReturnApplyDto;
import com.itheima.mall.mapper.omsMapper.OmsCompanyAddressMapper;
import com.itheima.mall.mapper.omsMapper.OmsOrderReturnApplyMapper;
import com.itheima.pojo.oms.OmsOrderReturnApply;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class OmsOrderReturnApplyApiImpl implements OmsOrderReturnApplyApi {
    @Autowired
    private OmsOrderReturnApplyMapper omsOrderReturnApplyMapper;

    @Override
    public void delete(Integer[] ids) {
        LambdaQueryWrapper<OmsOrderReturnApply> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(OmsOrderReturnApply::getId, ids);
        omsOrderReturnApplyMapper.delete(queryWrapper);

    }

    @Override
    public PageResult<OmsOrderReturnApply> list(OmsOrderReturnApplyDto dto, Integer pageNum, Integer pageSize) {
        Page<OmsOrderReturnApply> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<OmsOrderReturnApply> queryWrapper = new LambdaQueryWrapper<>();
        //条件查询
        queryWrapper.eq(StrUtil.isNotBlank(dto.getCreateTime()), OmsOrderReturnApply::getCreateTime, dto.getCreateTime());
        queryWrapper.eq(StrUtil.isNotBlank(dto.getHandleMan()), OmsOrderReturnApply::getHandleMan, dto.getHandleMan());
        queryWrapper.eq(StrUtil.isNotBlank(dto.getHandleTime()), OmsOrderReturnApply::getHandleTime, dto.getHandleTime());
        queryWrapper.eq((dto.getId()) != null, OmsOrderReturnApply::getId, dto.getId());
        queryWrapper.eq((dto.getStatus()) != null, OmsOrderReturnApply::getStatus, dto.getStatus());
        omsOrderReturnApplyMapper.selectPage(page,queryWrapper);
        PageResult<OmsOrderReturnApply> pageResult = new PageResult<>();
        pageResult.setTotal((int)page.getTotal());
        pageResult.setTotalPage((int)page.getPages());
        pageResult.setItems(page.getRecords());
        pageResult.setPageSize(pageSize);
        pageResult.setPageNum(pageNum);

        return pageResult;
    }

    @Override
    public OmsOrderReturnApply findById(Integer id) {
        return omsOrderReturnApplyMapper.selectById(id);
    }

    @Override
    public void updateById(Integer id, OmsOrderReturnApply omsOrderReturnApply) {
        omsOrderReturnApply.setId(id.longValue());
        omsOrderReturnApplyMapper.updateById(omsOrderReturnApply);
    }
}
